export default {
    data() {
        return {
            // 列表加载动画
            pageTableLoading: false,
            // 分页对象
            page: {
                page: 1,
                limit: 10,
                total: 0
            },
            // 表格数据
            tableData: [],
            // 分页数量
            pageSizes: [10, 20, 30, 50, 100],
            // 表头状态标识
            showHeader: true,
            // 列表选择项
            multipleSelection: []
        }
    },
    created() {
        this.$nextTick().then(() => {
            console.log('我是page table mixin')
        });
    },
    methods: {
        /**
         * 请求返回的回调
         * @param {*} apiResult
         * @returns {*} promise
         */
        setPageTableData(dataRows = {}) {
            return new Promise((resolve, reject) => {
                try {
                    this.pageTableLoading = false;
                    this.tableData = dataRows.list;
                    this.page.total = dataRows.totalCount;
                    // 直接抛出
                    resolve(this.tableData);
                } catch (error) {
                    reject(error);
                }
            });
        },
        // 开启加载动画
        openPageTableLoading() {
            this.pageTableLoading = true
        },
        /**
         * 错误时将pageTableLoading置为 false
         */
        closePageTableLoading() {
            this.pageTableLoading = false;
        },
        //切换页数
        handleSizeChange(val) {
            this.page.limit = val;
            this.getDataTable();
        },
        // 翻页
        handleCurrentChange(val) {
            this.page.page = val;
            this.getDataTable();
        },
        // 多选事件
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        // 切换显示搜索表头
        changeHeader() {
            this.showHeader = !this.showHeader
        },
        // 重置搜索表单
        handleFormReset() {
            this.$refs.searchForm.resetFields()
            this.$refs.groupTreeSelect.resetFields()
            this.$refs.orgTreeSelect.resetFields()
            this.$refs.deptTreeSelect.resetFields()
        },
    }
}